package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.bo.IDListBO;
import com.cskaoyan.bean.param.BaseParam;
import com.cskaoyan.bean.pojo.MarketAftersale;
import com.cskaoyan.bean.vo.AfterSaleListVO;
import com.cskaoyan.service.AfterSaleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 后台-商场管理模块
 * 创建日期: 2022/04/06 15:57
 *
 * @author ChengWenqi
 */

@RestController
@RequestMapping("admin/aftersale")
public class MarketAfterSaleController {

    @Autowired
    AfterSaleService afterSaleService;

    // 售后管理：/admin/aftersale/list
    @RequestMapping("list")
    public BaseRespVo aftersaleList(BaseParam param, String aftersaleSn, Integer orderId, Short status) {
        AfterSaleListVO afterSaleListVO = afterSaleService.queryAftersaleList(param, aftersaleSn, orderId, status);
        return BaseRespVo.ok(afterSaleListVO);
    }

    // 售后管理，批量通过：/admin/aftersale/batch-recept
    @RequestMapping("batch-recept")
    public BaseRespVo batchRecept(@RequestBody IDListBO ids) {
        List<Integer> idList = ids.getIds();
        int code = afterSaleService.batchRecept(idList);
        if (code == 200) {
            return BaseRespVo.ok();
        }
        return BaseRespVo.fail(10000, "售后订单已审核或不存在，无法通过！");
    }

    // 售后管理，单个通过：admin/aftersale/recept
    @RequestMapping("recept")
    public BaseRespVo recept(@RequestBody MarketAftersale aftersale) {
        int code = afterSaleService.recept(aftersale);
        if (code == 200) {
            return BaseRespVo.ok();
        }
        return BaseRespVo.fail(10000, "售后订单已审核或不存在，无法通过！");
    }

    // 售后管理，批量拒绝：/admin/aftersale/batch-reject
    @RequestMapping("batch-reject")
    public BaseRespVo batchReject(@RequestBody IDListBO ids) {
        List<Integer> idList = ids.getIds();
        int code = afterSaleService.batchReject(idList);
        if (code == 200) {
            return BaseRespVo.ok();
        }
        return BaseRespVo.fail(10000, "售后订单已审核或不存在，无法拒绝！");
    }

    // 售后管理，单个拒绝：admin/aftersale/reject
    @RequestMapping("reject")
    public BaseRespVo reject(@RequestBody MarketAftersale aftersale) {
        int code = afterSaleService.reject(aftersale);
        if (code == 200) {
            return BaseRespVo.ok();
        }
        return BaseRespVo.fail(10000, "售后订单已审核或不存在，无法拒绝！");
    }

    // 售后管理：单个退款，/admin/aftersale/refund
    @RequestMapping("refund")
    public BaseRespVo refund(@RequestBody MarketAftersale aftersale) {
        int code = afterSaleService.refund(aftersale);
        if (code == 200) {
            return BaseRespVo.ok();
        }
        return BaseRespVo.fail(10000, "售后订单不存在！");
    }

}
